<?php

namespace app\api\controller\questions;

use app\api\controller\Controllers;
use app\api\service\questions\QuestionCollection as QuestionCollectionService;

class QuestionCollection extends Controllers
{

    /**
     * 获取题目收藏
     * @param QuestionCollectionService $service
     * @param int $qid
     *
     * @return \think\Response
     */
    public function get(QuestionCollectionService $service, int $aid)
    {
        return $service->get($aid)->isEmpty()===false?success():notFound();
    }

    /**
     * 收藏/取消
     * @param QuestionCollectionService $service
     * @param int $aid
     *
     * @return \think\Response
     */
    public function collection(QuestionCollectionService $service,int $aid)
    {
        return $service->collection($aid)?success():failed('收藏/取消失败');
    }

    /**
     * 获取收藏列表
     * @param QuestionCollectionService $service
     *
     * @return \think\Response
     */
    public function lists( QuestionCollectionService $service )
    {
        $list = $service->lists();
        return false === $list->isEmpty()?success($list):notFound();
    }

    /**
     * 查看收藏题目
     * @param QuestionCollectionService $service
     *
     * @return \think\Response
     */
    public function read(QuestionCollectionService $service, int $id)
    {
        return success($service->read($id));
    }

}
